package com.um.jdy.platform.order.controller;

import com.um.jdy.platform.recharge.entity.dto.RechargeOrderPageDTO;
import com.um.jdy.platform.order.entity.dto.RefundDTO;
import com.um.jdy.platform.order.entity.vo.DepositOrderItemVO;
import com.um.jdy.platform.order.manager.DepositOrderManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 押金订单
 *
 * @author cs
 * 日期 2023/6/7
 * 版权所有 广州优匠科技有限公司
 */
@RestController
@RequestMapping("/api/v1/cms/deposit/order/")
@Api(tags = "押金订单")
@ApiPermission("deposit")
@TokenRequired
@Validated
public class DepositOrderController extends BaseController<DepositOrderManager> {


    /**
     * 分页查询订单
     *
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询订单")
    @PostMapping("page")
    public Response<Page<DepositOrderItemVO>> page(@RequestBody RechargeOrderPageDTO params) {
        PageParams pageParams = params.toPageParams(
                new String[]{"orderNo","outTradeNo","nickname","mobile"},
                new String[]{"o.order_no","o.out_trade_no","u.nickname","u.mobile"},
                "o.create_time","beginTime","endTime");
        return manager.page(pageParams);
    }

    /**
     * 押金退回
     *
     * @param refundDTO
     * @return
     */
    @ApiPermission("refund")
    @ApiOperation("押金退回")
    @PostMapping("refund")
    public Response refund(@Valid  @RequestBody RefundDTO refundDTO) throws Exception {
        return manager.refund(refundDTO);
    }

}
